<?php

namespace app\index\service;

use app\index\dao\HotRankDao;
use app\index\model\UM as UM;
use ShidianUtil\Utils\TimeUtil;
use think\Collection;
use think\exception\ValidateException;

/**
 * Class HotRankSourceService
 * @package app\index\service
 */
class HotRankSourceService
{
    // dao
    private HotRankDao $hotRankDao;

    public function __construct(HotRankDao $hotRankDao)
    {
        $this->hotRankDao = $hotRankDao;
    }

    /**
     * 案源消耗榜
     * @param UM|null $user
     * @param int|null $page
     * @param int|null $page_size
     * @return Collection
     */
    public function index(?UM $user, $timeCondition, ?int $page = null, ?int $page_size = null): Collection
    {
        $startTime = null;
        $endTime = time();

        if ($timeCondition === 'ALL') {

        } elseif ($timeCondition === 'D30') {
            $startTime = TimeUtil::stamp(TimeUtil::DAY, $endTime) - 30 * 86400;
        } elseif ($timeCondition === 'D7') {
            $startTime = TimeUtil::stamp(TimeUtil::DAY, $endTime) - 7 * 86400;
        } else {
            throw new ValidateException('不支持该类型表单');
        }

        return $this->hotRankDao->selectHotRankSource($startTime, $endTime, $page, $page_size);
    }
}
